package com.example.jimanguang.Entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "comments")
@Getter
@Setter
public class Comments extends BaseEntity{

    private String content;//评论内容

    @Temporal(TemporalType.TIMESTAMP)
    private Date CommentTime;//评论时间

    public Comments() {
        CommentTime =new Date();
    }

    //评论回复
    @OneToMany(mappedBy = "parentComment")
    private List<Comments> replayComments=new ArrayList<>();
    @ManyToOne
    private Comments parentComment;
    @ManyToOne
    private User user;
    @ManyToOne
    private Comics comics;

    @JsonBackReference
    public User getUser(){return user;}

    @JsonBackReference
    public  Comics getComics(){return comics;}
    @JsonManagedReference
    public  List<Comments> getReplayComments(){return replayComments;}
    @JsonBackReference
    public Comments getParentComment(){return parentComment;}
}
